<?php
$msg = '';
if (isset($_FILES["archive"])) {
	if ($_FILES["archive"]["error"] > 0) {
		$msg = "Error: " . $_FILES["file"]["error"];
	} else {
		$fileName = $_FILES["archive"]["name"];
		move_uploaded_file($_FILES["archive"]["tmp_name"], $fileName);

		$zip = new ZipArchive;
		$res = $zip->open($fileName);
		
		if ($res === TRUE) {
			$zip->extractTo('.');
			$zip->close();
			$msg = 'Success';
		} else {
			$msg = 'Error: can not extract archive.';
		}
	}
}

/*
$content = file_get_contents('application/db/1_schema.sql');
$content = preg_replace('/--.*\r\n/', '',$content);
$content = preg_replace('/\/.*\//', '',$content);
$queries = split(';', $content);
*/
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>Blog Setup</title>
</head>
<body>
	<p><?php echo $msg ?></p>
	<form method="post" enctype="multipart/form-data">
		<input type="file" name="archive" />
		<button type="submit">install</button><br/>
		<textarea style="width:100%; height: 700px"><?php echo $content ?></textarea>
	</form>
</body>